﻿using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace NetRosApp.Klijenti
{
    public partial class ReportSelectorFrm : XtraForm
    {
        public int tipispisa = 0;
        public ReportSelectorFrm()
        {
            InitializeComponent();
            pisaci.Properties.Items.AddRange(PrinterUtility.GetPrintere());
            pisaci.EditValue = PrinterUtility.GetPrinterToPrinter();
            kopija.EditValue = PrinterUtility.BrojKopija;
            radioGroup1.EditValue = PrinterUtility.PreglediliIspis;
            LBIzabir.DrawItem += new ListBoxDrawItemEventHandler(LBIzabir_DrawItem);
        }

        void LBIzabir_DrawItem(object sender, ListBoxDrawItemEventArgs e)
        {
            //Brush backBrush1 = new SolidBrush(Color.FromArgb(163, 224, 148));
            //Brush backBrush2 = new SolidBrush(Color.FromArgb(250, 250, 200));
            //Brush backBrush3 = new SolidBrush(Color.FromArgb(253, 192, 47));
            //  Brush backBrush4 = new SolidBrush(Color.FromArgb(123, 111, 34));
            // declare field representing the text of the item being drawn
            //string itemText = LBIzabir.GetItemText(e.Index);
            //if ((e.State & DrawItemState.Selected) != 0)
            //{
                
            //    e.Cache.FillRectangle(backBrush3, e.Bounds);
            //    ControlPaint.DrawBorder3D(e.Graphics, e.Bounds);
            //    e.Cache.DrawString(itemText, new Font(e.Appearance.Font.Name,
            //      e.Appearance.Font.Size, FontStyle.Bold), new SolidBrush(Color.Black),
            //      e.Bounds, e.Appearance.GetStringFormat());
            //    e.Handled = true;
            //    return;
            //}
            if ( e.Item as IzjestajiListe != null  && ((IzjestajiListe)e.Item).TipIspia == "Lokalno" &&  (e.State & DrawItemState.Selected) == 0)
            {
                 //itemText = ((IzjestajiListe)e.Item).Lokacija;
                 //e.Cache.FillRectangle(backBrush4, e.Bounds);
                 e.Cache.DrawString(LBIzabir.GetItemText(e.Index), e.Appearance.Font, new SolidBrush(Color.Blue),
                 e.Bounds, e.Appearance.GetStringFormat());
                 e.Handled = true;
            }
           
           
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }

        private void LBIzabir_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                DialogResult = DialogResult.OK;
                tipispisa = (int)radioGroup1.EditValue;
                Close();
            }
        }

        private void LBIzabir_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            DialogResult = DialogResult.OK;
            tipispisa = (int)radioGroup1.EditValue;
            Close();
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {

            DialogResult = DialogResult.OK;
            tipispisa = 0;
            Close();
        }

        private void pisaci_EditValueChanged(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(pisaci.EditValue as string))
            {
                PrinterUtility.SetPrinterToPrint(pisaci.EditValue as string);
            }
        }



        private void kopija_ValueChanged(object sender, EventArgs e)
        {
            PrinterUtility.BrojKopija = Convert.ToInt16(kopija.Value);
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {

            DialogResult = DialogResult.OK;
            tipispisa = 1;
            Close();

        }

        private void radioGroup1_Validated(object sender, EventArgs e)
        {
            PrinterUtility.PreglediliIspis = (int)radioGroup1.EditValue;
        }
    }
}